importPackage(net.sf.odinms.client);

var status = 0;
var randomz = 0;
var chosen = 0;
var itemz = Array(2022108,2022118,2022087,2022089,2022062,2022182,2012000,2022245,2022194,2022143,2022075,2022282,2022148,2022306,2022069,2022265,2022283,2022305,2022109);
var items = Array(1302020, 1302030, 1302064, 1312032, 1322054, 1332025, 1332055, 1332056, 1372034, 1382009, 1382012, 1382039, 1402039, 1412011, 1412027, 1422014, 1422029, 1422037, 1432012, 1432040, 1442024, 1442051, 1452016, 1452022, 1452045, 1462014, 1462019, 1462040, 1472030, 1472032, 1472055, 1482020, 1482021, 1482022, 1492020, 1492021, 1492022);
var mercury = Array(1102149, 1040138, 1041139, 1082225, 1060121, 1061142, 1072328, 1702150);
var tania = Array(1102148, 1040137, 1041138, 1082224, 1060120, 1061141, 1072327, 1702149);


function start() {
	status = -1;
	action(1, 0, 0);
}

function action(mode, type, selection) {
	if (mode == -1) {
		cm.dispose();
	} else {
		if (mode == 0) {
			cm.sendOk("Are you sure? Come back when you are");
   			cm.dispose();
   			return;
  		}
		if (mode == 1)
   			status++;
  		else
   			status--;
  		if (status == 0) {
			cm.sendYesNo("Hello there mighty mapler\r\nAre you in for a little game?");
		} else if (status == 1) {
			cm.sendSimple("Which of the following games?\r\n#b#L1#The Buff Game#l\r\n#L2#The Maple-Weapon Game#l\r\n#L3#The Red-or-Blue Game#l\r\n#L4#Mesos Game#l#k");
  		} else if (status == 2) {
			chosen = selection
			if (chosen == 1) {
				var text = "These are the available buffs:\r\n";
				for (var i = 0; i < itemz.length; i++) {
					text += ("#v" + itemz[i] + "#");
				}
				text += "\r\n\r\nPay me 5k and i will give you one of the buffs\r\nBut, some buffs will cancel some other buffs\r\nDo you want to give me 5 k?";
				cm.sendYesNo(text);
			} else if (chosen == 2) {
				var text = "These are the available Weapons:\r\n";
				for (var i = 0; i < items.length; i++) {
					text += ("#v" + items[i] + "#");
				}
				text += "\r\n\r\nGive me 2 Golden Boxes and i will give you one of the Weapons\r\nDo you want to give it a try?";
				cm.sendYesNo(text);
			} else if (chosen == 3)
				cm.sendSimple("#L1##rRed (Tania)#l\r\n#L2##bBlue (Mercury)#k#l");
			else 
   				cm.sendYesNo("Heres the deal, I will make you choose out of 3 options\r\nIf you pick the wrong one i will kill you and take 1k mesos\r\nIf you pick the correct one i will give you 10k mesos\r\nDo you still want to play it?");
  		} else if (status == 3) {
			if (chosen == 4)
				cm.sendSimple("#L1##rA#k#l #L2##bB#k#l #L3##gC#k#l");
			else if (chosen == 1) {
				if (cm.getMeso() >= 5000) {
					cm.gainMeso(-5000);
					cm.giveItemBuff(itemz[Math.floor(Math.random()*(itemz.length))]);
				} else {
					cm.sendOk("You dont have enough mesos");
				}
				cm.dispose();
			} else if (chosen == 3) {
				chosen = selection;
				if (chosen == 1) 
					cm.sendYesNo("Ah #rRed#k\r\nI need 10 Golden boxes from you and i will give you a random #rRed#k item!");
				else
					cm.sendYesNo("Ah #bBlue#k\r\nI need 10 Golden boxes from you and i will give you a random #bBlue#k item!");
			} else {
				if (cm.itemQuantity(4280000) >= 2) {
					if (cm.canHold(1302020)) {
						cm.gainItem(4280000, -2);
						cm.gainItem(items[Math.floor(Math.random()*(items.length))], 1);
						cm.sendOk("Thanks for the boxes, I gave you a maple weapon");
					} else {
						cm.sendOk("You don't have room for this weapon");
					}
				} else {
					cm.sendOk("You dont have enough boxes");
					cm.dispose();
				}
				cm.dispose();
			}
		} else {
			if (chosen == 4) {
				randomz = Math.floor(Math.random()*3+1);
				switch (selection) {
					case randomz:
						cm.gainMeso(10000);
						cm.sendOk("Congratulations, you have won");
						break;
					default:
						cm.sendOk("Too bad");
						cm.gainMeso(-10000);
						cm.getChar().setHp(0);
    						cm.getChar().setMp(0);
    						cm.getChar().updateSingleStat(MapleStat.HP, 0);
    						cm.getChar().updateSingleStat(MapleStat.MP, 0);
						break;
				}
			} else if (chosen == 1) {
				if (cm.itemQuantity(4280000) >= 10) {
					if (cm.canHold(1302020))
						cm.gainItem(tania[cm.getRandom(0, tania.length)], 1);
					else
						cm.sendOk("You don't have room for this item");
				} else {
					cm.sendOk("You don't have enough Golden Boxes");
				}
			} else if (chosen == 2) {
				if (cm.itemQuantity(4280000) >= 10) {
					if (cm.canHold(1302020))
						cm.gainItem(mercury[cm.getRandom(0, mercury.length)], 1);
					else
						cm.sendOk("You don't have room for this item");
				} else {
					cm.sendOk("You don't have enough Golden Boxes");
				}
			}
			cm.dispose();
		}
	}
}